//
//  BGBaseViewController.swift
//  WeiboSwift
//
//  Created by 战场原黑仪 on 16/7/19.
//  Copyright © 2016年 战场原黑仪. All rights reserved.
//

import UIKit

class BGBaseViewController: UIViewController {

    //判断是否登录
    var isLogin: Bool = BGUserAccountViewModel.sharedTools.isLogin
    
    //访客视图
    var visitView: BGVisitorView?
    
    
    //MARK: - 监听事件
    @objc private func loginClick() {
        
        let oauthVC = BGOAuthViewController()

        //modal方式
//        oauthVC.modalTransitionStyle = .PartialCurl
        
        presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
        
    }
    
    
    //MARK: - 界面
    override func loadView() {
        if isLogin {
            view = tableView
        }else {
            //访客视图
            visitView = BGVisitorView()
            visitView?.closure = {[weak self] in
                self?.loginClick()
            }
            view = visitView
            setupVisitorNav()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    //访客的navigationBar
    func setupVisitorNav() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: #selector(loginClick))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(loginClick))
    }
    
    
    //MARK: - 懒加载
    lazy var tableView: UITableView = {
        let tableView = UITableView()
        tableView.delegate = self
        tableView.dataSource = self
        return tableView
    }()
    
}

//MARK: - 代理方法
extension BGBaseViewController: UITableViewDelegate, UITableViewDataSource {
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 0
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("")
        return cell!
    }
}



